package com.zretc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.zretc.entity.Blog;

@Repository
public interface BlogMapper {
	/**
	 * 根据blogid来查询blog信息
	 * 
	 * @param id
	 * @return
	 */

	@Select("SELECT id,blogtitle,content FROM Blog  WHERE id=#{id}")
	public Blog selectBlog(int id);

	@Insert("insert into blog values(null,#{title},#{content},#{author.authorid})")
	public boolean addBlog(Blog blog);
	
	/**
	 * 分页+模糊查询
	 * @param start
	 * @param pageSize
	 * @param keywords
	 * @return
	 */
	@Select("SELECT blog.id,blog.blogtitle,blog.content,blog.state,author.authorid,author.authorname FROM Blog inner join author on author.authorid=blog.authorid  WHERE blog.blogtitle like concat(#{keywords},'%') limit #{start},#{pageSize}")
	@ResultMap(value="blogMap")
	public List<Blog> selectBlogsByLike(@Param("start") int start,@Param("pageSize") int limit,@Param("keywords") String keywords);
	
	
	
	
	/**
	 * 模糊查询得到总记录数
	 * @param keywords
	 * @return
	 */
	@Select("SELECT count(id) FROM Blog inner join author on author.authorid=blog.authorid WHERE blogtitle like concat(#{keywords},'%')")
	public int selectBlogsByLikeCount(@Param("keywords") String keywords);
	
	

	
	
}
